// Copyright 2011 and onwards Noam Shazeer and Georges Harik

#ifndef _INTSEQUENCES_H_
#define _INTSEQUENCES_H_

#include "util.h"
#include <vector>
#include <sstream>
#include <fstream>
#include <pthread.h>

// all this for turning "stripped" into sequences.bin"
struct Sequence {
  uint32 id_;
  vector<int64> v_;
  string description_;
  static Sequence MakeSequence(int32 id) { Sequence s; s.id_ = id; return s; }
};

// read a sequence from "stripped"
bool LoadSequence(istream &in, Sequence & s);
bool operator <(const Sequence &a, const Sequence &b);
bool IsPrefix(const Sequence &a, const Sequence &b);
bool operator ==(const Sequence &a, const Sequence &b);

struct SequenceIndex {

  char * GetDescription(int32 sequence_num) {
    return descriptions_[sequence_num];
  }
  
  int64 GetNumSequences() { return num_sequences_; }
  int64* GetSequence(int32 id) { return sequences_[id]; }
  int32 GetSequenceLength(int32 id) { return lengths_[id]; }

  // TODO: we might want to free memory on destruction

  void Load();

  // Store sequences in their original ID order
  int32 num_sequences_;
  int32 * lengths_;      // length of sequence i
  int32 * ranks_;        // rank of sequence i in lexicographic order
  int32 * rank_id_;      // going from rank to id
  char ** descriptions_; // description of sequence i
  int64 ** sequences_;   // sequence i integers
};

void MakeBinarySequenceFile();

void IntegerMakeExplicitProblemFile();

#endif
